import Vue from "vue";
import App from "./App.vue";
import router from "./router";
import store from "./store/store";
import api from "./api/api.js";
import mixins from "./mixins/mixins";
import dayjs from "dayjs"
import VueClipboard from 'vue-clipboard2' // 复制
import axios from 'axios'
Vue.prototype.$axios = axios    //全局注册，使用方法为:this.$axios
Vue.use(VueClipboard)

import echarts from "echarts";
Vue.prototype.$echarts = echarts;
// 引入element-ui组件
// import ElementUI from "element-ui";
// import "element-ui/lib/theme-chalk/index.css";
// import "element-ui/lib/theme-chalk/display.css";

// 引入自定义icon
import "@/assets/icon/iconfont.css";

// 引入全局样式global.styl
import "@/assets/css/global.styl";
// Vue.use(ElementUI);

import tinymce from 'vue-tinymce-editor'
Vue.component('tinymce', tinymce)

// 全局组件 ImgPreview
import ImgPreview from './components/ImgPreview'
Vue.component('img-preview', ImgPreview)

// 阻止启动生产提示
Vue.config.productionTip = false;

// 全局调用api
Vue.prototype.$api = api;
Vue.prototype.$dayjs = dayjs;

// 全局调用store
Vue.prototype.$store = store;

// 使用混入mixins
Vue.mixin(mixins);

new Vue({
  router,
  store,
  render: h => h(App),
}).$mount("#app");

if (process.env.NODE_ENV == 'production') {
  window.onload = function () {
    setTimeout(function () {
      let t = performance.timing
      console.log('DNS查询耗时 ：' + (t.domainLookupEnd - t.domainLookupStart).toFixed(0))
      console.log('TCP链接耗时 ：' + (t.connectEnd - t.connectStart).toFixed(0))
      console.log('request + response请求耗时 ：' + (t.responseEnd - t.responseStart).toFixed(0))
      console.log('白屏时间 ：' + (t.responseStart - t.navigationStart).toFixed(0))
      console.log('domready时间 ：' + (t.domContentLoadedEventEnd - t.navigationStart).toFixed(0))
      console.log('解析dom树耗时 ：' + (t.domComplete - t.domInteractive).toFixed(0))
      console.log('onload时间 ：' + (t.loadEventEnd - t.navigationStart).toFixed(0))
      console.log('所有资源加载耗时：', performance.getEntries())
      if (t = performance.memory) {
        console.log('js内存使用占比 ：' + (t.usedJSHeapSize / t.totalJSHeapSize * 100).toFixed(2) + '%')
      }
    })
  }
}

// 钩子函数路由判断
router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    if (localStorage.token) {
      next();
    } else {
      next({
        path: "/login",
        // 带上参数登录后根据参数返回原页面
        query: { redirect: router.currentRoute.fullPath }
      });
    }
  } else {
    next();
  }
});
